#encoding: utf-8
load 'rds_api.rb'
load 'tutem_utils.rb'

@rds = @rds_tt

# name:   spreader-change-checker
# usage:  检查变动了推广者但历史数据尚未同步的用户，予以重新计算

def sync_spreader_changed_users

    sql = "select uid from tutem_mall.eb_user where need_sync = 1"
    results = @rds.query(sql)

    # 遍历查询结果并调用syncUser(uid)
    results.each do |row|
        uid = row['uid']
        syncUserData uid
        sql = "update tutem_mall.eb_user set need_sync = 0 where uid = #{uid}"
        @rds.query(sql);
        puts "synced"
    end
end

sync_spreader_changed_users
